<template>
  <div class="wapper">
    <el-container style="100%">
      <el-main style="background:#fff;">
        <div class="table-wrap" v-show="listShow">
          <div class="handle-box3">
            <el-form :inline="true" ref="form" :model="searchForm" class="demo-form-inline">
              <div class="uers-left">
                 <el-form-item label="搜索：">
                  <el-input v-model="searchForm.name" placeholder="名称"></el-input>
                </el-form-item>
                 <el-form-item label="">
                  <el-input v-model="searchForm.phone" placeholder="手机"></el-input>
                </el-form-item>
                <el-form-item label="等级：">
                  <el-select v-model="searchForm.level" placeholder="选择等级">
                    <el-option
                      label="全部"
                      value="-1">
                      <div  @click="getChangeType(-1)">全部</div>
                    </el-option>
                    <el-option
                      label="1级"
                      value="0">
                      <div  @click="getChangeType(0)">1级</div>
                    </el-option>
                    <el-option
                      label="2级"
                      value="1">
                      <div  @click="getChangeType(1)">2级</div>
                    </el-option>
                    <el-option
                      label="3级"
                      value="2">
                      <div @click="getChangeType(2)">3级</div>
                    </el-option>
                    <el-option
                      label="4级"
                      value="3">
                      <div @click="getChangeType(3)">4级</div>
                    </el-option>
                    <el-option
                      label="5级"
                      value="4">
                      <div @click="getChangeType(4)">5级</div>
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="searchSubmit">搜索</el-button>
              </div>
              <div class="uers-right">
                <span class="btn-r">
                  <el-button type="primary" plain icon="el-icon-plus" @click="addSubmit">新增</el-button>
                </span>
              </div>
            </el-form>
          </div>
          <div class="tabbox">
          <el-table
            :data="dataList"
            height="100%"
            border
            class="tabbox"
            ref="multipleTable"
            :header-cell-style="{background:'#f2f6fc',color:'#606266'}"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column prop="phone" label="赠票地址" align="center" width="200">
              <template slot-scope="scope">
                <span>{{url+"/t/"+ scope.row.ticketComplimentaryId}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="姓名" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.name}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="level" label="等级" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.level+1}}级</span>
              </template>
            </el-table-column>
            <el-table-column prop="phone" label="手机" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.phone}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="typeName" label="票类型" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.typeName}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="total" label="总量" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.total}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="useNumber" label="已使用量" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.useNumber}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="createDate" label="创建日期" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.createDate}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                <el-button type="text" class="red" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table></div>
          <div class="fb"><el-pagination
            class="pag"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            background
          ></el-pagination></div>
        </div>
        <DeleteDialog
          :delVisible="delVisible"
          @deleteData="deleteData"
          @handleCloseVisible="handleCloseVisible"
        ></DeleteDialog>
        <EditDisManage :editShow="editShow" :editData="editData" @backFunStu="getFunStu"></EditDisManage>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import EditDisManage from "../../../components/ticketing/ticket/EditDisManage";
import TicketType from "../../../components/ticketing/ticket/TicketType";
import DeleteDialog from "../../../components/public/DeleteConfim";

export default {
  data() {
    return {
      total: 0, //总条数
      currentPage: 1, //初始页
      pagesize: 10, // 每页的数据
      //表格高度适配
      tabheight: "",
      searchForm: {
        name: "",
        phone:"",
        level:"-1"
      },
      url:localStorage.getItem('url').replace('/api',''),
      projectId:localStorage.getItem('project_Id'),
      TicketType:[],
      editData: {},
      listShow: true,
      delVisible: false,
      ticketCom_Id: "",
      editShow: false,
      dataList: [],
      multipleSelection: []
    };
  },
  mounted() {
    // this.tabheight=(this.$refs.getheight.offsetHeight-165)
  },
  created() {
    this.getData();
    this.getTicketType();
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
    handleEdit(index, row) {
      this.editData = row;
      this.listShow = false;
      this.editShow = true;
    },
    searchSubmit() {
      var search = {
        name: this.searchForm.name,
        pageIndex: this.currentPage - 1,
        pageSize: this.pagesize,
        level: this.searchForm.level,
        phone: this.searchForm.phone,
        projectId:this.projectId
      }
      this.$axios.post('/TicketComplimentary/Search',search)
        .then(res =>{
          if (res.data.hasError == false) {
            this.dataList = [...res.data.data]
            this.total = res.data.total;
          }
        })
    },
    // 获取数据
    getData() {
      this.searchSubmit();
    },
    addSubmit() {
      this.listShow = false;
      this.editShow = true;
    },
    handleDelete(index, row) {
      this.ticketCom_Id = row.ticketComplimentaryId;
      this.delVisible = true;
    },
    deleteData() {
      this.$axios.delete(`/TicketComplimentary/${this.ticketCom_Id}`)
        .then(res =>{
            this.$message.success("删除成功！");
            this.delVisible = false
            this.getData();
        })
    },
    getTicketType(){
      this.$axios.get('/TicketType/Project/'+this.projectId).then(res =>{
        if (res.data.hasError == false) {
          this.TicketType = [...res.data.data]
        }
      })
    },
    getChangeType(type){
      this.searchForm.level = type;
    },
    handleCloseVisible() {
      this.ticketCom_Id = "";
      this.delVisible = false;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getFunStu() {
      this.listShow = true;
      this.editShow = false;
      this.getData();
    }
  },
  components: {
    EditDisManage,
    TicketType,
    DeleteDialog
  }
};
</script>
<style lang="scss" scope>
.pag {
  position: absolute;
  bottom: 0;
}
.table-wrap {
  height: 100%;
  margin-left: 10px;
}
.el-main{
  border-radius: 5px;
  position: relative;
}
.uers-left {
  float: left;
}
.uers-right {
  float: right;
}
.el-dialog{height: auto;}
</style>